package com.yang.studentsapp.presenter;


import com.hyphenate.exceptions.HyphenateException;
import com.yang.studentsapp.model.IActionLogin;
import com.yang.studentsapp.model.IActionRegister;
import com.yang.studentsapp.model.IActionSend;
import com.yang.studentsapp.model.IActionSuccess;
import com.yang.studentsapp.model.ModeAccount;
import com.yang.studentsapp.model.ModleContact;

/**
* Created by MVPHelper on 2016/10/10
*/

public class SettingPresenterImpl extends SettingPresenter{
    /**
     * 操作账号相关的Mode
     */
    private ModeAccount mModeAccount;
    ModleContact modleContact;
    /**
     * 构造函数
     * @param
     */
    public SettingPresenterImpl() {
        mModeAccount = new ModeAccount();
        modleContact = new ModleContact();
    }

    /**
     * 注册的帐号
     * @param name 注册的帐号
     * @param pwd 密码
     * @param register
     */
    public void register(String name, String pwd, final IViewRegister register,
                         final IViewSuccess<String> actionSucces) {
        mModeAccount.register(name, pwd, new IActionRegister() {
            @Override
            public void start(int textId) {
                register.onStart(textId);
            }

            @Override
            public void regesterError(HyphenateException error) {
                register.onRegisterError(error);
            }

        }, new IActionSuccess<String>() {
            @Override
            public void succes(String response) {
                actionSucces.onSuccess(response);
            }
        });
    }

    public void login(String name, String pwd, final IViewLogin iViewLogin) {
        mModeAccount.login(name, pwd, new IActionLogin() {
            @Override
            public void error(String error) {
                iViewLogin.error(error);
            }

            @Override
            public void start(String msg) {
                iViewLogin.start(msg);
            }

            @Override
            public void succes(String response) {
                iViewLogin.onSuccess(response);
            }
        });
    }

    public void addContact(String name, String addReason, final IViewSend iViewSend) {
        modleContact.addContact(name, addReason, new IActionSend() {
            @Override
            public void start(String mag) {
                iViewSend.start(mag);

            }

            @Override
            public void error(String mag) {
                iViewSend.error(mag);
            }

            @Override
            public void succes(String data) {
                iViewSend.onSuccess(data);
            }
        });
    }

    public void addContactAdded(String newContactadded) {
        modleContact.addContactAdded(newContactadded);

    }
}